package com.ketangpai.admin.controller;

import com.ketangpai.admin.entity.Task;
import com.ketangpai.admin.entity.TaskNumber;
import com.ketangpai.admin.service.TaskManagementService;
import com.ketangpai.admin.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/taskManagement")
@Api(tags = "任务管理")
public class TaskManagementController {
    @Resource
    private TaskManagementService taskManagementService;

    @ApiOperation(value = "获取任务列表")
    @PostMapping("/type")
    public JsonResult<?> selectTaskManagement(@RequestBody(required = true) Map<String, Object> params) {
        Integer userId = (Integer) params.get("userId");
        String type = (String) params.get("type");
        if (userId == null) {
            return JsonResult.error("userId不能为空");
        }
        Task[] tasks = taskManagementService.selectTaskManagement(userId,type);
        Map<String, Object> result = new HashMap<>();
        result.put("taskList", tasks);
        return JsonResult.success(result);
    }

    @ApiOperation(value = "获取任务列表数量")
    @PostMapping("/number")
    public JsonResult<?> getTaskNumber(@RequestBody(required = true) Map<String, Integer> params) {
        Integer userId = params.get("userId");
        if (userId == null) {
            return JsonResult.error("userId不能为空");
        }
        TaskNumber taskNumber = taskManagementService.getTaskNumber(userId);
        System.out.println(taskNumber);
        return JsonResult.success(taskNumber);
    }
}
